<extend name="Public/baseConf" />
<block name="breadcrumb"> 
	<div class="row wrapper border-bottom white-bg page-heading">
	    <div class="col-lg-8">
	        <h2><if condition="ACTION_NAME eq 'add'">新增<else/>编辑</if>模型</h2>
	        <ol class="breadcrumb">
	            <li><a href="{:U('index/index')}">首页</a></li>
	            <li><a href="{:U('Model/index')}">模型列表</a></li>
	            <li class="active">
	                <strong><if condition="ACTION_NAME eq 'add'">新增<else/>编辑</if>模型</strong>
	            </li>
	        </ol>
	    </div>
	    <div class="col-lg-4">
            <div class="title-action">
 				<button class="btn btn-primary ajax-post" type="submit" target-form="form-horizontal"><i class="fa fa-check"></i>保存</button>
	            <a class="btn btn-warning" type="submit" href="{:U('index')}"><i class="fa fa-reply"></i>返回</a>
            </div>
        </div>
	</div>  
</block>
<block name="body">
	<div class="row">
	    <div class="col-lg-12">
		<div class="tabs-container">
		<ul class="nav nav-tabs">
			<li class="active"><a data-toggle="tab"  href="#tab1"><i class="green fa fa-user  bigger-110"></i>基 础</a></li>
			<li><a data-toggle="tab"  href="#tab2"><i class="green fa fa-user  bigger-110"></i>设 计</a></li>
			<li><a data-toggle="tab"  href="#tab3"><i class="green fa fa-user  bigger-110"></i>高 级</a></li>
		</ul>
		<!-- 表单 -->
		<form id="form" action="{:U('update')}" method="post" class="form-horizontal">
			<!-- 基础 -->
			<div class="tab-content" >
				<div id="tab1" class="tab-pane in active">
				<div class="panel-body">
					<div class="form-group">
						<label class="col-sm-4 control-label no-padding-right">模型标识<small>（请输入文档模型标识）</small></label>
						<div class="col-sm-8">
							<input type="text" class="form-control " name="name" value="{$info.name}">
						</div>
					</div>
					<div class="hr-line-dashed"></div>
					<div class="form-group">
						<label class="col-sm-4 control-label no-padding-right">模型名称<small>（请输入模型的名称）</small></label>
						<div class="col-sm-8">
							<input type="text" class="form-control " name="title" value="{$info.title}">
						</div>
					</div>
					<div class="hr-line-dashed"></div>
					<div class="form-group">
						<label class="col-sm-4 control-label no-padding-right">模型类型<small>（目前只支持独立模型和文档模型）</small></label>
						<div class="col-sm-8">
							<select name="extend" class='form-control'>
								<option value="0">独立模型</option>
								<option value="1">文档模型</option>
							</select>
						</div>
					</div>
					<div class="hr-line-dashed"></div>
				</div>
				</div>
				<div id="tab2" class="tab-pane">
				<div class="panel-body">
					<div class="form-group">
						<label class="col-sm-4 control-label no-padding-right">字段管理<small>（只有新增了字段，该表才会真正建立）</small></label>
						<div class="col-sm-8">
							<div class="form-group edit_sort edit_sort_l form_field_sort">
								<span>字段列表 	[ <a href="{:U('Attribute/add?model_id='.$info['id'])}" target="_balnk">新增</a>
								<a href="{:U('Attribute/index?model_id='.$info['id'])}" target="_balnk">管理</a> ] </span>
								<foreach name="fields" item="field" key="k">
									<div class="checkbox checkbox-info">
                             			<input id="{$field['title']}{$field['name']}" type="checkbox" name="attribute_list[]" value="{$field['id']}" 
											<if condition="in_array($field['id'],$info['attribute_list'])">checked="checked"</if> />
                                        <label for="{$field['title']}{$field['name']}"> {$field['title']} <a class="text-navy"><strong>[{$field['name']}]</strong></a> </label>
                                    </div>
								</foreach>
							</div> 
						</div>
					</div>
					<div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label no-padding-right">字段别名定义<small>（用于表单显示的名称）</small></label>
                        <div class="col-sm-8">
                                <textarea class="form-control" name="attribute_alias">{$info.attribute_alias}</textarea>
                        </div>
                    </div>
					<div class="hr-line-dashed"></div>
					<div class="form-group">
						<label class="col-sm-4 control-label no-padding-right">表单显示分组<span>（用于表单显示的分组，以及设置该模型表单排序的显示）</span></label>
						<div class="col-sm-8">
							<input type="text" class="form-control" name="field_group" value="{$info.field_group}">
						</div>
					</div>
					<div class="hr-line-dashed"></div>
					<div class="form-group">
						<label class="col-sm-4 control-label no-padding-right">表单显示排序<small>（直接拖动进行排序）</small></label>
						<div class="col-sm-8">
						<volist name=":parse_field_attr($info['field_group'])" id="vo">
							<div class="form-group edit_sort edit_sort_l form_field_sort">
								<span>{$vo}</span>
								<ul class="dragsort needdragsort" data-group="{$key}">
									<foreach name="fields" item="field" key="k">
										<if condition="(($field['group'] eq $key) or($i eq 1 and !isset($field['group']))) and ($field['is_show'] eq 1)">
											<li class="getSort">
												<em data="{$field['id']}">{$field['title']} [{$field['name']}]</em>
												<input type="hidden" name="field_sort[{$key}][]" value="{$field['id']}"/>
											</li>
										</if>
									</foreach>
								</ul>
							</div>
						</volist>
						</div>
					</div>
					<div class="hr-line-dashed"></div>

					<div class="form-group">
						<label class="col-sm-4 control-label no-padding-right">列表定义<small>（默认列表模板的展示规则）</small></label>
						<div class="col-sm-8">
								<textarea  class="form-control" name="list_grid">{$info.list_grid}</textarea>
						</div>
					</div>
					<div class="hr-line-dashed"></div>

					<div class="form-group">
						<label class="col-sm-4 control-label no-padding-right">默认搜索字段<small>（默认列表模板的默认搜索项）</small></label>
						<div class="col-sm-8">
							<input type="text" class="form-control" name="search_key" value="{$info.search_key}">
						</div>
					</div>
					<div class="hr-line-dashed"></div>
					<div class="form-group">
						<label class="col-sm-4 control-label no-padding-right">高级搜索字段<small>（默认列表模板的高级搜索项）</small></label>
						<div class="col-sm-8">
							<input type="text" class="form-control" name="search_list" value="{$info.search_list}">
						</div>
					</div>
					<div class="hr-line-dashed"></div>
				</div>
				</div>
				<!-- 高级 -->
				<div id="tab3" class="tab-pane">
				<div class="panel-body">
					<div class="form-group">
						<label class="col-sm-4 control-label no-padding-right">列表模板<small>（自定义的列表模板，放在Application\Admin\View\Think下，不写则使用默认模板）</small></label>
						<div class="col-sm-8">
							<input type="text" class="form-control" name="template_list" value="{$info.template_list}">
						</div>
					</div>
					<div class="hr-line-dashed"></div>
					<div class="form-group">
						<label class="col-sm-4 control-label no-padding-right">新增模板<small>（自定义的新增模板，放在Application\Admin\View\Think下，不写则使用默认模板）</small></label>
						<div class="col-sm-8">
							<input type="text" class="form-control" name="template_add" value="{$info.template_add}">
						</div>
					</div>
					<div class="hr-line-dashed"></div>
					<div class="form-group">
						<label class="col-sm-4 control-label no-padding-right">编辑模板<small>（自定义的编辑模板，放在Application\Admin\View\Think下，不写则使用默认模板）</small></label>
						<div class="col-sm-8">
							<input type="text" class="form-control" name="template_edit" value="{$info.template_edit}">
						</div>
					</div>
					<div class="hr-line-dashed"></div>
					<div class="form-group">
						<label class="col-sm-4 control-label no-padding-right">列表数据大小<small>（默认列表模板的分页属性）</small></label>
						<div class="col-sm-8">
							<input type="text" class="form-control" name="list_row" value="{$info.list_row}">
						</div>
					</div>
					<div class="hr-line-dashed"></div>
				</div>
				</div>
			</div>
			<input type="hidden" name="id" value="{$info['id']}"/>
		</form>
	</div>
	</div>
</div>
</block>
<block name="script">
	<script type="text/javascript" src="__STATIC__/jquery.dragsort-0.5.1.min.js"></script>
	<script type="text/javascript" charset="utf-8">
	Think.setValue("extend", {$info.extend|default=0}); 
	//拖曳插件初始化
	$(function(){
		$(".needdragsort").dragsort({
		     dragSelector:'li',
		     placeHolderTemplate: '<li class="draging-place">&nbsp;</li>',
		     dragBetween:true,	//允许拖动到任意地方
		     dragEnd:function(){
		    	 var self = $(this);
		    	 self.find('input').attr('name', 'field_sort[' + self.closest('ul').data('group') + '][]');
		     }
		 });
	})
	</script>
</block>

